package backtrack_Recursion;

import java.util.Scanner;

public class QuestionTwo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int T = scanner.nextInt();
        while(T-- > 0){
            String s = scanner.nextLine().trim();
            StringBuilder t = new StringBuilder();

            //t.setLength(0);
            int p = 0;
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                if(c == 'R'){
                    if(p != 0){
                        int len = t.length();
                        if(len > 0){
                            p = p % len;
                            if(p != 0){
                                t.append(t.subSequence(0,p));
                                t.delete(0,p);
                            }
                        }
                        p = 0;
                    }
                    t.reverse();
                }else if(Character.isLetter(c)){
                    if(p != 0){
                        int len = t.length();
                        if(len > 0){
                            p = p % len;
                            if(p != 0){
                                t.append(t.subSequence(0,p));
                                t.delete(0,p);
                            }
                        }
                        p = 0;
                    }
                    t.append(c);
                }
                else if(Character.isDigit(c)){
                    int digital = c - '0';
                    if(t.length() == 0){
                        continue;
                    }
                    if(p == 0){
                        p = digital;
                    }else{
                        p = p * 10 + digital;
                    }
                    int len = t.length();
                    if(len > 0){
                        p = p % len;
                    }
                }
            }
            if(p != 0){
                int len = t.length();
                if(len > 0){
                    p = p % len;
                    if(p != 0){
                        t.append(t.subSequence(0,p));
                        t.delete(0,p);
                    }
                }
            }
            System.out.println(t.toString());
        }
    }
}
